package net.tv90.bfmccore.battlepack;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static net.tv90.bfmccore.battlepack.Battlepack.getBattlepack;
import static net.tv90.bfmccore.battlepack.Battlepack.openBattlepack;

public class BattlepackCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (label.equalsIgnoreCase("bp")) {
            if (args[0].equalsIgnoreCase("open")) {
                if (sender instanceof Player) {
                    openBattlepack((Player) sender);
                }
            }
            if (args[0].equalsIgnoreCase("give")) {
                if (sender instanceof Player && !sender.isOp()) return true;
                try{
                    EnumBattlepackLevel enumBattlepackLevel = EnumBattlepackLevel.valueOf(args[1].toUpperCase());
                    Player player = Bukkit.getPlayerExact(args[2]);
                    getBattlepack(player, enumBattlepackLevel);
                } catch (Exception e){
                    sender.sendMessage("/bp give <战斗包等级> <玩家>");
                    sender.sendMessage("战斗包等级:bronze silver gold weapon premium");
                    e.printStackTrace();
                }
            }
            return true;
        }
        return true;
    }
}
